#!/usr/bin/env python3
# -*- coding: utf-8 -*-

''
import json

info = {}
with open(r'C:\Users\admin\Desktop\r.csv', 'r') as f:
    while True:
        line = f.readline()
        if line:
            data = line.split(',')
            drug = data[0]
            dieases = data[1].split(' ')
            for diease in dieases:
                diease = diease.strip()
                if diease in info:
                    drugs = info.get(diease)
                    drugs.append(drug)
                    info[diease] = drugs
                else:
                    info.setdefault(diease, [drug])
        else:
            break

print(info)

for key,value in info.items():
    info[key] = list(set(value))

with open(r'json1.json','w') as f:
    json.dump(info, f, ensure_ascii=False)
